import os
import logging
import sys

from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.api import users

class LoginPage(webapp.RequestHandler):
	def get(self):
		user = users.GetCurrentUser()
		if user:
			# User is already logged in. Redirect to home page of the user
			self.redirect("home")
		else:
			# Display the login link. On clicking the link and logging in, that page should redirect back to this page
			# and thus should get redirected to the user's home page

			self.response.headers['Content-Type'] = "text/html"
			self.response.out.write('''
				<html>
					<head> 
						<title> DVD Share </title> 
           	<link rel="stylesheet" type="text/css" href="/static/styles.css" />
            <link rel="stylesheet" type="text/css" href="/static/list.css" />
					</head>

					<body>

            <div class="header" id="header_container">
              <div class="header" id="header_wrapper">
                <span class="header" id="header_title">
                  <h1 class="header"> DVDshare</h1><h2 class="header">.com</h2>
                </span>
                <span class="header" id="header_nav">
                  <a class="header nav_item" href="#"> about </a>
                  <a class="header nav_item" href="#"> how it works </a>
                  <a class="header nav_item last_item" href="#"> contact </a>
                </span>
              </div>
            </div>

           	<div class="content_container">
							<h1> Click <a href="%s">here</a> to login to DVD Share using your google account </h1>
						</div>

            <div class="footer">
              <h2 class="footer"> &copy;  2010 Enthupreneurs Inc </h2>
            </div>

					</body>

				</html>
				''' % (users.create_login_url(self.request.path)))
						
	
application = webapp.WSGIApplication([('/kumar/', LoginPage)], debug=True)
				 
def main():
	# main entry point

	util.run_wsgi_app(application);	
	

if __name__ == "__main__":
	main()
	
